using System;
using System.Collections.Generic;
using System.Web;

using Model;
using BLL.WWW_WWW.Wiki;
using Model.WWW_WWW.Wiki;

namespace BLF.WWW_WWW.Wiki
{

	/// <summary>
	/// Contains methods for formatting content using a pipeline paradigm.
	/// </summary>
    public static class FormattingPipeline
    {

        /// <summary>
        /// Performs the Phases 1 and 2 of the formatting process.
        /// </summary>
        /// <param name="raw">The Raw WikiMarkup to format.</param>
        /// <param name="current">The current Page, if any.</param>
        /// <returns>The formatted content.</returns>
        public static string FormatWithPhase1And2(string raw, PageInfo current)
        {
            PageInfo[] tmp;
            return FormatWithPhase1And2(raw, current, out tmp);
        }

        /// <summary>
        /// Performs the Phases 1 and 2 of the formatting process.
        /// </summary>
        /// <param name="raw">The Raw WikiMarkup to format.</param>
        /// <param name="current">The current Page, if any.</param>
        /// <param name="linkedPages">The Pages linked by the current Page.</param>
        /// <returns>The formatted content.</returns>
        public static string FormatWithPhase1And2(string raw, PageInfo current, out PageInfo[] linkedPages)
        {
            string username = HttpContext.Current.User.Identity.Name;
            bool admin = SessionFacade.Admin;
            
            // Phase 1
            raw = MultilanguageContentPlugin.Format(raw,current);

            PageInfo[] lnk;

            raw = Formatter.Format(raw, current, out lnk);

            // Phase 2
            raw = MultilanguageContentPlugin.Format(raw, current);

            linkedPages = lnk;

            return raw;
        }

        /// <summary>
        /// Performs the Phase 3 of the formatting process.
        /// </summary>
        /// <param name="raw">The Raw WikiMarkup to format.</param>
        /// <param name="current">The current Page, if any.</param>
        /// <returns>The formatted content.</returns>
        public static string FormatWithPhase3(string raw, PageInfo current)
        {
            raw = Formatter.FormatPhase3(raw, current);
            string username = HttpContext.Current.User.Identity.Name;
            bool admin = SessionFacade.Admin;
            // Phase 3
            raw = MultilanguageContentPlugin.Format(raw, current);
            return raw;
        }

    }

}
